package com.ezerg.boot.autoconfig;

import javax.annotation.Resource;

import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConditionalOnClass({SayHello.class})
@EnableConfigurationProperties({SayHelloProperties.class})
@ConditionalOnProperty(prefix="hello",value="say",matchIfMissing=true)
public class SayHelloAutoConfiguration {
	@Resource
	private SayHelloProperties sayHelloProperties;
	
	@Bean
	@ConditionalOnMissingBean({SayHello.class})
	public SayHello sayHello() {
		SayHello sh = new SayHello();
		sh.setHello(sayHelloProperties.getSay());
		System.out.println("sayHello = " + sh.getHello());
		return sh;
	}
}
